package cn.mado.org.controller;

import cn.mado.basic.note.SysLog;
import cn.mado.basic.util.AjaxResult;
import cn.mado.basic.util.PageList;
import cn.mado.org.domain.Movie;
import cn.mado.org.domain.Novel;
import cn.mado.org.query.MovieQuery;
import cn.mado.org.query.NovelQuery;
import cn.mado.org.service.MovieService;
import cn.mado.org.service.NovelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/movie")
public class MovieController {

    @Autowired
    private MovieService movieService;

    /**
     * 查询部门全部
     */
    @GetMapping
    public List<Movie> findAll() {
        return movieService.findMovieAll();
    }

    /**
     * 添加、修改部门
     */
    @SysLog("新增修改了一个电影")
    @PostMapping("save")
    public AjaxResult addOrUpdate(@RequestBody Movie movie){
        System.out.println("我来："+movie);
        if (null == movie.getMovieId()){
            // 添加
            movieService.addMovie(movie);
        }else {
            // 修改
            movieService.updataMovie(movie);
        }
        return AjaxResult.me().success();
    }
    /**
     * 删除 delete localhost:8080/movie/1
     */
    @SysLog("id删除电影")
    @DeleteMapping("/{movieId}")
    public AjaxResult delete(@PathVariable("movieId") Long movieId){
        System.out.println(movieId);
        movieService.delMovieByid(movieId);
        return AjaxResult.me().success();
    }


    /**
     *
     * 分页查询
     */

    @PostMapping
    public PageList<Movie> queryByPage(@RequestBody MovieQuery query){
        List<Movie> nove = movieService.findMovie(query);
        Integer integer = movieService.findMovieTotals(query);
        return new PageList<>(integer,nove);
    }
}
